package com.linlz.write;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;


public class Demo2 {
    public static void main(String[] args) throws IOException {
        //1.创建工作簿
        XSSFWorkbook workbook = new XSSFWorkbook();
        //2.创建工作表
        XSSFSheet sheet = workbook.createSheet("工作表一");
        //3.创建行
        XSSFRow row = sheet.createRow(0);
        //4.创建单元格
        row.createCell(0).setCellValue("姓名");
        row.createCell(1).setCellValue("电话");

        XSSFRow row1 = sheet.createRow(1);
        row1.createCell(0).setCellValue("邓紫棋");
        row1.createCell(1).setCellValue("13900001111");

        FileOutputStream out = new FileOutputStream("C:\\Users\\112\\Desktop\\demo2.xlsx");

        workbook.write(out);

        //刷新
        out.flush();
        //关闭资源
        out.close();
        workbook.close();
        System.out.println("写入成功");
    }
}
